home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 3.8 KB | 162 lines | [TEXT/CWIE] |
- #ifndef __TRAPS__
- # include <Traps.h>
- #endif
-
- #ifndef __RESOURCES__
- # include <Resources.h>
- #endif
-
- #ifndef __A4STUFF__
- # include <A4Stuff.h>
- #endif
-
- #ifndef __DISPLAYS__
- # include <Displays.h>
- #endif
-
- enum { kBottomPixels = 25 };
-
- typedef pascal void (*vInitGDevice)
- (short qdRefNum, long mode, GDHandle gdh);
-
- static GDHandle gStripDevice;
- static vInitGDevice gInitGDevice;
-
- extern pascal OSErr CallOldDMMoveDisplay
- (GDHandle moveDevice, short x, short y, Handle displayState, UniversalProcPtr)
- = {0x303C, 0x0609, 0x2F17, 0x41FA, 0x0008, 0x2F48, 0x0004, 0x4E75};
-
- static UInt16 GetRowBytes (UInt16 rowBytes)
- {
- return 0x7FFF & rowBytes;
- }
-
- static UInt16 GetRowBytes (PixMapHandle pmh)
- {
- return GetRowBytes ((**pmh).rowBytes);
- }
-
- static UInt16 GetRowBytes (GDHandle gdh)
- {
- return GetRowBytes ((**gdh).gdPMap);
- }
-
- static pascal void AdjustStripDevice (void)
- {
- GDHandle mainDevice = ::GetMainDevice ( );
- PixMapHandle mainDevicePixMap = (**mainDevice).gdPMap,
- stripDevicePixMap = (**gStripDevice).gdPMap;
-
- (**mainDevice).gdRect.bottom -= kBottomPixels;
- (**mainDevicePixMap).bounds.bottom -= kBottomPixels;
-
- (**gStripDevice).gdRect.top = (**mainDevice).gdRect.bottom;
- (**stripDevicePixMap).bounds.top = (**mainDevicePixMap).bounds.bottom;
-
- UInt32 stripDeviceHeight =
- (**mainDevice).gdRect.bottom - (**mainDevice).gdRect.top;
- UInt32 baseAddrOffset =
- stripDeviceHeight * GetRowBytes (mainDevicePixMap);
-
- (**stripDevicePixMap).baseAddr += baseAddrOffset;
-
- (**gStripDevice).gdFlags = (**mainDevice).gdFlags;
- SetDeviceAttribute (gStripDevice,ramInit,false);
- SetDeviceAttribute (gStripDevice,mainScreen,false);
- }
-
- static pascal void InitGDevicePatch (short qdRefNum, long mode, GDHandle gdh)
- {
- long preservedA4 = SetCurrentA4 ( );
-
- GDHandle mainDevice = ::GetMainDevice ( );
-
- if (gdh == gStripDevice)
- gdh = mainDevice;
-
- gInitGDevice (qdRefNum,mode,gdh);
-
- if (gdh == mainDevice)
- {
- gInitGDevice ((**mainDevice).gdRefNum, (**mainDevice).gdMode, gStripDevice);
- AdjustStripDevice ( );
- }
-
- SetA4 (preservedA4);
- }
-
- static pascal OSErr MoveDisplayPatch
- (GDHandle moveDevice, short x, short y, Handle displayState, UniversalProcPtr old)
- {
- long preservedA4 = SetCurrentA4 ( );
-
- OSErr err = noErr;
-
- if (gStripDevice != moveDevice)
- err = CallOldDMMoveDisplay (moveDevice,x,y,displayState,old);
-
- SetA4 (preservedA4);
-
- return err;
- }
-
- static pascal asm UniversalProcPtr DisplayDispatchPatchAsm (UniversalProcPtr)
- {
- MOVE.L (SP)+,A1
- LEA @hack1+2,A0
- MOVE.L (SP),(A0)
- LEA @hack2+2,A0
- MOVE.L (SP)+,(A0)
- LEA @patch,A0
- MOVE.L A0,(SP)
- JMP (A1)
- @patch:
- CMPI.W #0x0609,D0
- BEQ @moveDisplay
- @hack1:
- JMP 'hack'
- @moveDisplay:
- MOVE.L (SP),-(SP) // dup return address; make room for...
- @hack2:
- MOVE.L #'hack',4(SP) // ...old DisplayDispatch address
- JMP MoveDisplayPatch // 'call'
- RTS // make disassembler happy
- }
-
- extern void __Startup__ (void);
-
- pascal void main (void)
- {
- long preservedA4 = SetCurrentA4 ( );
-
- struct { QDGlobals qd; QDGlobalsPtr qdp; } qdGlobals;
- long preservedA5 = SetA5 (long (&(qdGlobals.qdp)));
- InitGraf (&(qdGlobals.qd.thePort));
-
- if (GDHandle mainDevice = ::GetMainDevice ( ))
- {
- gStripDevice = ::NewGDevice ((**mainDevice).gdRefNum, (**mainDevice).gdMode);
-
- if (gStripDevice)
- {
- AdjustStripDevice ( );
-
- (**gStripDevice).gdNextGD = (**mainDevice).gdNextGD;
- (**mainDevice).gdNextGD = Handle (gStripDevice);
-
- ::DetachResource (::Get1Resource ('INIT',0));
- // ::DetachResource (::RecoverHandle (Ptr (__Startup__)));
-
- UniversalProcPtr upp = ::GetToolTrapAddress (_DisplayDispatch);
- upp = ::DisplayDispatchPatchAsm (upp);
- ::SetToolTrapAddress (upp,_DisplayDispatch);
-
- gInitGDevice = vInitGDevice (::GetToolTrapAddress (_InitGDevice));
- ::SetToolTrapAddress (UniversalProcPtr (InitGDevicePatch), _InitGDevice);
- }
- }
-
- (void) SetA5 (preservedA5);
- (void) SetA4 (preservedA4);
- }
-